package com.ruoyi.ly.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ruoyi.ly.domain.MobileQrcode;
import com.ruoyi.ly.domain.dto.MobileQrcodeAddDTO;
import com.ruoyi.ly.domain.dto.MobileQrcodeUpdateDTO;
import com.ruoyi.ly.domain.dto.PageMobileQrcodeDTO;
import com.ruoyi.ly.domain.vo.MobileQrcodeVO;
import com.ruoyi.ly.domain.vo.PageMobileQrcodeVO;
import com.ruoyi.ly.mapper.MobileQrcodeMapper;
import com.ruoyi.ly.service.MobileQrcodeService;
import com.ruoyi.ly.utils.PageResult;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MobileQrcodeServiceImpl implements MobileQrcodeService {

    @Autowired
    private MobileQrcodeMapper mobileQrcodeMapper;

    @Override
    public void update(MobileQrcodeUpdateDTO mobileQrcodeUpdateDto) {
        MobileQrcode mobileQrcode =new MobileQrcode();
        BeanUtils.copyProperties(mobileQrcodeUpdateDto,mobileQrcode);
        mobileQrcodeMapper.update(mobileQrcode);
    }

    @Override
    public void save(MobileQrcodeAddDTO mobileQrcodeAddDTO) {
        MobileQrcode mobileQrcode =new MobileQrcode();
        BeanUtils.copyProperties(mobileQrcodeAddDTO,mobileQrcode);
        mobileQrcode.setCreateTime(String.valueOf(System.currentTimeMillis()));
        mobileQrcodeMapper.insert(mobileQrcode);
    }

    @Override
    public PageResult pageQuery(PageMobileQrcodeDTO pageMobileQrcodeDTO) {
        PageHelper.startPage(pageMobileQrcodeDTO.getPage(), pageMobileQrcodeDTO.getPageSize());
        Page<PageMobileQrcodeVO> page = mobileQrcodeMapper.pageQuery(pageMobileQrcodeDTO);
        long total = page.getTotal();
        List<PageMobileQrcodeVO> records = page.getResult();
        return new PageResult(total,records);
    }

    @Override
    public void delete(Long id) {
        mobileQrcodeMapper.delete(id);
    }

    @Override
    public MobileQrcodeVO selectById(Long id) {
        MobileQrcodeVO mobileQrcodeVO = mobileQrcodeMapper.selectById(id);
        return mobileQrcodeVO;
    }
}
